# coding=utf-8
# 供typora调用，将tpyora复制到本地仓库的图片提交并push到远程仓库，同时生成

import os
import sys
import shutil
import git

base_repo_dir = os.path.dirname(os.path.realpath(__file__))

def img_to_remote(img_path):
    os.chdir(base_repo_dir)
    # repo = git.Repo(base_repo_dir)
    img_name = os.path.basename(img_path)
    shutil.move(img_path, f"{base_repo_dir}/assets")

    # repo.index.add(f"./assets/{img_name}")
    # repo.index.commit("add image")
    # remote = repo.remote()
    # remote.push("master")
    os.system("git add .")
    os.system('git commit -m "add image"')
    os.system("git push")
    img_remote_url = f"https://yanyuzuixin.gitee.io/imagebed/{img_name}"
    print(img_remote_url)

for i in range(1, len(sys.argv)):
    img_to_remote(sys.argv[i])

